﻿using System.Drawing;
using System.IO;
using System.Linq;

namespace Kindler.IO.MobiFile
{
    class Program
    {
        static void Main(string[] args)
        {
            string moboFilePath = @"C:\Users\Scriv\Documents\My Publications\MSDN Blogs\MSDN Blogs.txt";

            byte[] allBytes = File.ReadAllBytes(moboFilePath);

            IMobiFileReader reader = new MobiFileReader();
            MobiFile file = reader.Read(allBytes);

            MobiFileHeader header = file.GetHeader();
            string title = file.GetFullName();

            using (StreamWriter writer = File.CreateText(@"c:\book.htm"))
            {
                writer.Write(file.GetHtml());
            }

            var stream = new MemoryStream(file.Records.ElementAt(((int)header.FirstImageIndex) + 2).Value);
            Image image = Bitmap.FromStream(stream);

            image.Save(@"c:\image.jpeg");
        }
    }
}